import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/assets_tool/images.dart';
import 'package:tiktokadult/config/config.dart';
import 'package:tiktokadult/hj_page/web_page/h5_page.dart';

import '../../../../config/address.dart';
import '../../../../tools_base/net/net_manager.dart';

class FloatingRewardView extends StatefulWidget {
  final Function? closeCallBack;

  FloatingRewardView({this.closeCallBack});

  @override
  State<StatefulWidget> createState() {
    return _FloatingRewardViewState();
  }
}

class _FloatingRewardViewState extends State<FloatingRewardView> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    if (Config.activeUrl?.isNotEmpty != true) return SizedBox();
    return GestureDetector(
      onTap: () async {
        String token = await netManager.getToken();
        Get.to(
          H5Page(
            url: Config.activeUrl! + "&token=" + token + "&appUrl=" + Address.baseHost!,
            title: "抽奖",
          ),
        );
      },
      child: Container(
        width: 74,
        height: 74,
        child: Stack(
          fit: StackFit.expand,
          children: [
            Positioned(
              bottom: 0,
              child: Image.asset(
                "home_lottory_icon.gif".homePath,
                width: 74,
                height: 74,
              ),
            ),
            Positioned(
              right: 0,
              top: 0,
              child: GestureDetector(
                onTap: () {
                  widget.closeCallBack?.call();
                },
                behavior: HitTestBehavior.translucent,
                child: Padding(
                  padding: EdgeInsets.fromLTRB(8, 0, 0, 8),
                  child: Image.asset(
                    'close_grey.png'.commonImgPath,
                    width: 16,
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}
